/**
 * Created by web-01 on 2018/3/5.
 */
/*
* 功能一，点击"全部图书"下的四大类"畅销"，"最新"，"价格", "免费"，展现出不同的东西
* */
$(()=>{
    //1
    $utd = $("div.u-nav-tab>ul>li.item>a.utd");
    $utd.click(function(e){
        e.preventDefault();
        var list = $(this).data("list");
        // console.log(list);
        $("."+list).show().siblings().hide();
        //2
        var i = $(this).parent().index();
        // console.log(i);
        $(".box").css("left", i*64);
        //3
        $(this).parent().addClass("crt").siblings().removeClass("crt");
    });
    // 动态导入数据， 畅销
    $.ajax({
        type:"GET",
        url:"data/products/getSoldCount.php",
        dataTpye:"json",
        success:function(data){
            var html = "";
            for(var item of data){
                html += `<li class="u-bookitm1">
                        <div class="cover">
                            <a href="#">
                                <img src="${item.pic_sm}" alt="${item.author}">
                            </a>
                            <div class="u-price">
                                <em>¥ ${item.price}</em>
                                <del>¥ ${item.del_price}</del>
                            </div>
                        </div>
                        <div class="info">
                            <a class="title" href="#">${item.title}</a>
                            <div class="u-stargrade">
                                <div class="icon"></div>
                                <span class="num"> ( 20 ) </span>
                            </div>
                            <div class="author">
                                <span>${item.author}</span>
                            </div>
                            <p class="desc">${item.subtitle}</p>
                        </div>
                        <div class="act">
                            <span>
                                <a class="icon-cart" href="javascirpt:;"></a>
                                <a class="icon-heart" href="javascirpt:;"></a>
                            </span>
                        </div>
                    </li>`;
            }
            $("ul.sell").html(html);
        },
        error:function(){alert("网络故障请检查");}
    });
    // 动态导入数据，最新
    $.ajax({
        type:"GET",
        url:"data/products/getPublishTime.php",
        dataTpye:"json",
        success:function(data){
            var html = "";
            for(var item of data){
                html += `<li class="u-bookitm1">
                        <div class="cover">
                            <a href="#">
                                <img src="${item.pic_sm}" alt="${item.author}">
                            </a>
                            <div class="u-price">
                                <em>¥ ${item.price}</em>
                                <del>¥ ${item.del_price}</del>
                            </div>
                        </div>
                        <div class="info">
                            <a class="title" href="#">${item.title}</a>
                            <div class="u-stargrade">
                                <div class="icon"></div>
                                <span class="num"> ( 20 ) </span>
                            </div>
                            <div class="author">
                                <span>${item.author}</span>
                            </div>
                            <p class="desc">${item.subtitle}</p>
                        </div>
                        <div class="act">
                            <span>
                                <a class="icon-cart" href="javascirpt:;"></a>
                                <a class="icon-heart" href="javascirpt:;"></a>
                            </span>
                        </div>
                    </li>`;
            }
            $("ul.new").html(html);
        },
        error:function(){alert("网络故障请检查");}
    });
    // 动态导入数据，评价 就是普通的 哈哈哈
    $.ajax({
        type:"GET",
        url:"data/products/getBookEvaluate.php",
        dataTpye:"json",
        success:function(data){
            var html = "";
            for(var item of data){
                html += `<li class="u-bookitm1">
                        <div class="cover">
                            <a href="#">
                                <img src="${item.pic_sm}" alt="${item.author}">
                            </a>
                            <div class="u-price">
                                <em>¥ ${item.price}</em>
                                <del>¥ ${item.del_price}</del>
                            </div>
                        </div>
                        <div class="info">
                            <a class="title" href="#">${item.title}</a>
                            <div class="u-stargrade">
                                <div class="icon"></div>
                                <span class="num"> ( 20 ) </span>
                            </div>
                            <div class="author">
                                <span>${item.author}</span>
                            </div>
                            <p class="desc">${item.subtitle}</p>
                        </div>
                        <div class="act">
                            <span>
                                <a class="icon-cart" href="javascirpt:;"></a>
                                <a class="icon-heart" href="javascirpt:;"></a>
                            </span>
                        </div>
                    </li>`;
            }
            $("ul.evaluate").html(html);
        },
        error:function(){alert("网络故障请检查");}
    });
    // 动态导入数据，价格
    $.ajax({
        type:"GET",
        url:"data/products/getPriceAsc.php",
        dataTpye:"json",
        success:function(data){
            var html = "";
            for(var item of data){
                html += `<li class="u-bookitm1">
                        <div class="cover">
                            <a href="#">
                                <img src="${item.pic_sm}" alt="${item.author}">
                            </a>
                            <div class="u-price">
                                <em>¥ ${item.price}</em>
                                <del>¥ ${item.del_price}</del>
                            </div>
                        </div>
                        <div class="info">
                            <a class="title" href="#">${item.title}</a>
                            <div class="u-stargrade">
                                <div class="icon"></div>
                                <span class="num"> ( 20 ) </span>
                            </div>
                            <div class="author">
                                <span>${item.author}</span>
                            </div>
                            <p class="desc">${item.subtitle}</p>
                        </div>
                        <div class="act">
                            <span>
                                <a class="icon-cart" href="javascirpt:;"></a>
                                <a class="icon-heart" href="javascirpt:;"></a>
                            </span>
                        </div>
                    </li>`;
            }
            $("ul.price").html(html);
        },
        error:function(){alert("网络故障请检查");}
    });
});